<?php
class Model_User extends System_App_Model_Abstract{
	protected $table = 'user';
	
	public static $structure = array(
		'id'=>array( 'type'=>'int', 'editable'=>'hidden' )
		,'nom'=>array( 'type'=>'string', 'editable'=>'input', 'max' => 255 )
		,'prenom'=>array( 'type'=>'string', 'editable'=>'input', 'max' => 255 )
		,'email'=>array( 'type'=>'mail', 'editable'=>'input', 'max' => 512 )
		,'password'=>array( 'type'=>'mail', 'editable'=>'password', 'max' => 12 )
                ,'role'=>array( 'type'=>'string', 'editable'=>'none' )
	);
	
	private $_id;
	private $_nom;
	private $_prenom;
	private $_email;
	private $_password;
	private $_role;
	
	public function login($login,$mdp){
		$query = 'SELECT id FROM user WHERE email="' . $login . '" AND password="' . $mdp . '" LIMIT 1';
		$result = $this->database->getQueryResult( $query, true );
		return $this->getEntity( $result['id'] );
	}
	
	public function toArray(){
		return array(
			'id'=>$this->getId()
			,'nom'=>$this->getNom()
			,'prenom'=>$this->getPrenom()
			,'email'=>$this->getEmail()
			,'password'=>$this->getPassword()
                        ,'role'=>$this->getRole()
		);
	}
	
	/* getter */
	public function getId(){
		return $this->_id;
	}
	public function getNom(){
		return $this->_nom;
	}
	public function getPrenom(){
		return $this->_prenom;
	}
	public function getEmail(){
		return $this->_email;
	}
	public function getPassword(){
		return $this->_password;
	}
        public function getRole(){
		return $this->_role;
	}
	
	/* setter */
	public function setId( $value ){
		$this->_id = $value;
	}
	public function setNom( $value ){
		$this->_nom = $value;
	}
	public function setPrenom( $value ){
		$this->_prenom = $value;
	}
	public function setEmail( $value ){
		$this->_email = $value;
	}
	public function setPassword( $value ){
		$this->_password = $value;
	}
        public function setRole( $value ){
		$this->_role = $value;
	}
}
?>